//
//  FileCache.m
//  AFNetworking
//
//  Created by baboy on 2019/2/13.
//

#import <Foundation/Foundation.h>
#import "BKKit.h"
#import "FileCache.h"

NSString * getBundleFilePath(NSString *fn, NSBundle *bundle){
    if (bundle == nil) {
        bundle = [NSBundle mainBundle];
    }
    
    DLOG(@"bundle:%@,%@", bundle,[bundle bundlePath]);
    NSString *fp = [[bundle bundlePath] stringByAppendingPathComponent:fn];
    if ([[NSFileManager defaultManager] fileExistsAtPath:fp]) {
        return fp;
    }
    DLOG(@"");
    return nil;
}
NSString * getStorageFilePath(NSString *fn, NSString *dir){
    NSString *rootDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *cacheDir = [rootDir stringByAppendingPathComponent:@"cache"];
    NSString *d = dir?[cacheDir stringByAppendingPathComponent:dir]:cacheDir;
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if(![fileManager fileExistsAtPath:d]){
        if(![fileManager createDirectoryAtPath:d withIntermediateDirectories:NO attributes:nil error:nil]){
            return nil;
        }
    }
    NSString *fp = d;
    if(fn){
        fp = [d stringByAppendingPathComponent:fn];
    }
    return fp;
}
